Skip to content
This repository was archived by the owner on Jul 14, 2025. It is now read-only.

FIX: Discourse automation reports with parameters#363

Merged
Drenmi merged 2 commits intomainfrom
fix/report-generator-parameters
Mar 13, 2025
Merged

FIX: Discourse automation reports with parameters#363
Drenmi merged 2 commits intomainfrom
fix/report-generator-parameters

Conversation

@Drenmi
Copy link
Copy Markdown
Contributor

@Drenmi Drenmi commented Mar 13, 2025

What is the problem?

When setting up an automation to create a DM or a post with a report on a recurring basis, and using a Data Explorer query that has parameters, we encounter an error.

Why is this happening?

The .params_to_hash currently expects an array of arrays for the parameters, e.g.:

[["group_name", "admins"]]

but in reality they seem to be arrays of hashes:

[{ "key" => "group_name", "value" => "admins" }]

How come we only found out now?

We do have tests for the report generator, and we do pass query parameters to it, but 1) we hard-code the parameters as an array of arrays and 2) the parameters aren't in the query used as a fixture.

How does this fix it?

This change makes ReportGenerator.params_to_hash work with arrays of hashes. It also preserves the ability to work with nested arrays in case this is used somewhere else.

build_report_post(query, table, attach_csv: opts[:attach_csv], result:)
end

private
Copy link
Copy Markdown
Contributor Author

@Drenmi Drenmi Mar 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scoping keywords put in the class body only affect instance methods. All methods in this class are class methods and therefore already public.

Comment on lines -42 to -55
params_hash = {}

if !params.blank?
param_key, param_value = [], []
params.flatten.each.with_index do |data, i|
if i % 2 == 0
param_key << data
else
param_value << data
end
end

params_hash = Hash[param_key.zip(param_value)]
end
Copy link
Copy Markdown
Contributor Author

@Drenmi Drenmi Mar 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This chunk is the same as Array#to_h.

@Drenmi Drenmi force-pushed the fix/report-generator-parameters branch from 451153d to 27a17da Compare March 13, 2025 09:33
@Drenmi Drenmi merged commit 41ee039 into main Mar 13, 2025
6 checks passed
@Drenmi Drenmi deleted the fix/report-generator-parameters branch March 13, 2025 09:50
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants